#include "unbalanced_adaboost.h"

double get_beta(int & argc, char **& argv) {
	double beta = atof(argv[0]);
	argc--;
	argv++;
	return beta;
}

void adapted_initialize_distribution(double * d, double * y, int l, double beta) {
	int pl = 0;
	for(int i = 0; i < l; i++) {
		if(y[i] == 1) {
			pl ++;
		}
	}

	double pw = beta / pl;
	double nw = (1 - beta) / (l - pl);

	for(int i = 0; i < l; i++) {
		if(y[i] == 1) {
			d[i] = pw;
		} else {
			d[i] = nw;
		}
	}
}

void unbalanced_adaboost::train_initialization(int & argc, char **& argv) {
	beta = get_beta(argc, argv);
}

void unbalanced_adaboost::initialize_distribution(double * d, double * y, int l) {
	return adapted_initialize_distribution(d, y, l, beta);
}

void unbalanced_real_adaboost::train_initialization(int & argc, char **& argv) {
	beta = get_beta(argc, argv);
}
void unbalanced_real_adaboost::initialize_distribution(double * d, double * y, int l) {
	return adapted_initialize_distribution(d, y, l, beta);
}
